import React from 'react';
import { Button, message } from 'antd';
import CommonList from '../../../../../../components/CommonLists/list';
import Modal from '../../../../../../components/Modal';
import services from '../../../../../../services/api';

class AuthorizeInfoList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'authorizeInfo';
    this.btnGroup = [
      (record) => (
        <Button type='link' onClick={() => this.delete(record)}>
          删除
        </Button>
      ),
    ];
  }

  delete = ({ appKeyId }) => {
    const {
      value: { id },
    } = this.props;
    Modal.open({
      title: '',
      width: '360px',
      isConfirm: true,
      content: <p>移除后appkey用户不能调用此接口,请确认通知用。</p>,
      isOkBtn: true,
      isCancelBtn: true,
      ok: () => {
        services[this.api].delete(appKeyId, id).then((data) => {
          if (data.code === 0) {
            message.success(data.message);
            this.props.queryList();
            Modal.close();
          } else {
            message.error(data.message);
          }
        });
      },
      cancel: () => {
        Modal.close();
      },
    });
  };
}

export default AuthorizeInfoList;
